package io.github.quickmsg.core.auth;

import io.github.quickmsg.common.auth.AuthManager;
import io.github.quickmsg.common.auth.enums.ConnectReasonEnum;
import io.github.quickmsg.common.config.AuthConfig;
import reactor.core.publisher.Mono;

/**
 * @author luxurong
 */
public class FixedAuthManager extends AbstractAuthManager {


    public FixedAuthManager(AuthConfig authConfig) {
        super(authConfig);
    }

    @Override
    public Mono<ConnectReasonEnum> auth(String userName, byte[] passwordInBytes, String clientIdentifier) {
        if(getAuthConfig().getFixed().getUsername().equals(userName)
                && getAuthConfig().getFixed().getPassword().equals(new String(passwordInBytes))){
            return Mono.just(ConnectReasonEnum.SUCCESS);
        }
        return Mono.just(ConnectReasonEnum.USERNAME_PASSWORD_ERROR);
    }
}
